PreviousNextTracker indexSee it online !

(52/185) 125 - sidekick: custom CompletionPopup

I'd like the ability to extend the SidekickCompletionPopup class so that I can display additional information about the completion, as in the screenshot attached (from eclipse).
It can be done in many ways, here one possible implementation: the SidekickParser could have a getCompletionPopup class like this:

public CompletionPopup getCompletionPopup( View view, int caretPosition, SideKickCompletion complete, boolean active){
return new SideKickCompletionPopup(view, this,
caretPosition, complete, active){
/\*\* forget reference to this popup when it is disposed \*/
public void dispose()
{
super.dispose();
popup = null;
}
};

}

}

Submitted rfrancois - 2009-04-02 08:30:40 Assigned
Priority 5 Labels
Status open Group None
Resolution None

Comments

2009-04-02 08:30:40
rfrancois

Screenshot.png (62.7Kio)

2009-04-02 08:38:47
rfrancois

Sorry, I pressed "Add artifact" too soon.

AFAICS, the only place where a CompletionPopup is created in sidekick is in the SidekickActions class, so the call :

popup = new SideKickCompletionPopup(view, parser,
textArea.getCaretPosition(), complete, active)
{
/\*\* forget reference to this popup when it is disposed \*/
public void dispose()
{
super.dispose();
popup = null;
}
};


coulld be replaced by :

popup = parser.getCompletionPopup( view, extArea.getCaretPosition(), complete, active) ;

2009-04-02 12:54:58
rfrancois

Screenshot-2.png (22.2Kio)

2009-04-02 12:59:28
rfrancois

With the proposed "design", I've achieved the Screenshot attached by extending slightly the SideKickCompletionPopup associated with my parser. I would be happy to send a formal patch if needed.

The component on the right is a JEditorPane that shows an html page, but we could imagine other things, such as for example a jedit text area showing the surroundings of where the current variable is created, ...

2009-04-02 13:49:44
*anonymous

How did you achieve that? Did you create your own Candidates implementation and use the renderer to find the selected item?

2009-04-02 14:04:25
rfrancois

Almost. Sidekick defines the Candidates interface as a private class within SidekickCompletion, so there is a little I can do with it from outside, but I took inspiration from this approach.

However, the SideKickCompletion class offers the possibility to override the getRenderer method, responsible to render __one__ completion, I believe this is passed to the Candidates interface eventually. So you write a custom renderer (in my case using a JTable as the component): see this (http://www.velocityreviews.com/forums/t149702-jtable-in-jcombobox.html) for example.

My getListCellRendererComponent method looks like this:

public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
if (isSelected) {
// update the editor pane here
}
}

For the component that extends SidekickCompletionPopup, I took your TagCompletionPopup (in CtagsInterface) as a starting point, and did something like this in the constructor

{
super( view, parser, caret, complete, active ) ;

editor = new JEditorPane( "text/plain", "" ) ;
editor.setSize( 400, editor.getFontMetrics(editor.getFont()).getHeight() \* Math.max(10, complete.size() + 2) ) ;
Container left = getContentPane();
JPanel p = new JPanel(
new VariableGridLayout(VariableGridLayout.FIXED_NUM_ROWS, 1) );
p.add(left );
JScrollPane pane = new JScrollPane(editor) ;
p.add(pane);
setContentPane(p);
}

2009-04-02 19:06:18
rfrancois

sidekick.diff (1.7Kio)